﻿using System.Drawing;
using System.Windows.Forms.Properties;
using GMap.NET.WindowsForms;
using GMap.NET.WindowsForms.ToolTips;
using GMap.NET.WindowsForms.Markers;
using GMap.NET;

namespace VehicleTrackingProject.Classes
{
    public enum enumGMapMarker
    {
        Rectangle = 1,
        Circle = 2,
        Star = 3,
        Image = 4
    }

   public class GMapMarkerRect : GMapMarker
   {
      public Pen Pen;

      public GMarkerGoogle InnerMarker;

      public GMapMarkerRect(PointLatLng p)
         : base(p)
      {
         Pen = new Pen(Brushes.Blue, 5);

         // do not forget set Size of the marker
         // if so, you shall have no event on it ;}
         Size = new System.Drawing.Size(111, 111);
         Offset = new System.Drawing.Point(-Size.Width/2, -Size.Height/2); 
          
      }

      public override void OnRender(Graphics g)
      {
         g.DrawRectangle(Pen, new System.Drawing.Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height));
      }
   }

   public class GMapMarkerEllipse : GMapMarker
   {
       public Pen Pen;

       public GMarkerGoogle InnerMarker;

       public GMapMarkerEllipse(PointLatLng p)
           : base(p)
       {
           Pen = new Pen(Brushes.Yellow, 5);

           // do not forget set Size of the marker
           // if so, you shall have no event on it ;}
           Size = new System.Drawing.Size(111, 111);
           Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);
       }

       public override void OnRender(Graphics g)
       {
           g.DrawEllipse(Pen, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
       }
   }

   public class GMapMarkerStar : GMapMarker
   {
       public Pen Pen;

       public GMarkerGoogle InnerMarker;

       public GMapMarkerStar(PointLatLng p)
           : base(p)
       {
           Pen = new Pen(Brushes.Pink, 5);

           // do not forget set Size of the marker
           // if so, you shall have no event on it ;}
           Size = new System.Drawing.Size(111, 111);
           Offset = new System.Drawing.Point(-Size.Width / 2, -Size.Height / 2);
       }

       public override void OnRender(Graphics g)
       {
           //g.DrawEllipse(Pens.Red, LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
           //pe.Graphics.Clear(BackColor);
           int StarCount = 1;
           int StarSpacing = 2;
           Rectangle[] m_starAreas = new Rectangle[StarCount];
           Rectangle drawArea =
                   new Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);

           for (int i = 0; i < StarCount; ++i)
           {
               m_starAreas[i].X = drawArea.X - StarSpacing / 2;
               m_starAreas[i].Y = drawArea.Y;
               m_starAreas[i].Width = drawArea.Width + StarSpacing / 2;
               m_starAreas[i].Height = drawArea.Height;

               DrawStar(g, drawArea, i);

               drawArea.X += drawArea.Width + StarSpacing;
           }
       }

       protected void DrawStar(Graphics g, Rectangle rect, int starAreaIndex)
       {
           Brush fillBrush;
           Color OutlineColor = Color.Red;
           Color BackColor = Color.Transparent;
           float OutlineThickness = 5;
           Pen outlinePen = new Pen(OutlineColor, OutlineThickness);

           //if (m_hovering && m_hoverStar > starAreaIndex)
           //{
           //    fillBrush = new LinearGradientBrush(rect,
           //           HoverColor, BackColor, LinearGradientMode.ForwardDiagonal);
           //}
           //else if ((!m_hovering) && m_selectedStar > starAreaIndex)
           //{
           //    fillBrush = new LinearGradientBrush(rect,
           //           SelectedColor, BackColor, LinearGradientMode.ForwardDiagonal);
           //}
           //else
           //{
               fillBrush = new SolidBrush(BackColor);
           
           //}

           PointF[] p = new PointF[10];
           p[0].X = rect.X + (rect.Width / 2);
           p[0].Y = rect.Y;
           p[1].X = rect.X + (42 * rect.Width / 64);
           p[1].Y = rect.Y + (19 * rect.Height / 64);
           p[2].X = rect.X + rect.Width;
           p[2].Y = rect.Y + (22 * rect.Height / 64);
           p[3].X = rect.X + (48 * rect.Width / 64);
           p[3].Y = rect.Y + (38 * rect.Height / 64);
           p[4].X = rect.X + (52 * rect.Width / 64);
           p[4].Y = rect.Y + rect.Height;
           p[5].X = rect.X + (rect.Width / 2);
           p[5].Y = rect.Y + (52 * rect.Height / 64);
           p[6].X = rect.X + (12 * rect.Width / 64);
           p[6].Y = rect.Y + rect.Height;
           p[7].X = rect.X + rect.Width / 4;
           p[7].Y = rect.Y + (38 * rect.Height / 64);
           p[8].X = rect.X;
           p[8].Y = rect.Y + (22 * rect.Height / 64);
           p[9].X = rect.X + (22 * rect.Width / 64);
           p[9].Y = rect.Y + (19 * rect.Height / 64);

           g.FillPolygon(fillBrush, p);
           g.DrawPolygon(outlinePen, p);
       }
   }

   public class GMapMarkerImage : GMapMarker
   {
       static readonly System.Drawing.Size SizeSt = new System.Drawing.Size(VehicleTrackingProject.Properties.Resources.wi0064_48.Width, VehicleTrackingProject.Properties.Resources.wi0064_48.Height);

       public GMapMarkerImage(PointLatLng p)
           : base(p)
       {
           Size = SizeSt;
           //Offset = new Point(-10, -34);
           Offset = new Point(0, 0);
       }

       //static readonly Point[] Arrow = new Point[] { new Point(-7, 7), new Point(0, -22), new Point(7, 7), new Point(0, 2) };

       public override void OnRender(Graphics g)
       {
           //if (!Bearing.HasValue)
           //{
           //    g.DrawImageUnscaled(Resources.shadow50, LocalPosition.X, LocalPosition.Y);
           //}
           //g.TranslateTransform(ToolTipPosition.X, ToolTipPosition.Y);

           //if (Bearing.HasValue)
           //{
           //    g.RotateTransform(Bearing.Value - Overlay.Control.Bearing);
           //    g.FillPolygon(Brushes.Lime, Arrow);
           //}

           //g.ResetTransform();

           //if (!Bearing.HasValue)
           //{
           //Rectangle drawArea = new Rectangle(LocalPosition.X, LocalPosition.Y, Size.Width, Size.Height);
           //g.DrawImage(VehicleTrackingProject.Properties.Resources.wi0064_48, drawArea);
           g.DrawImage(VehicleTrackingProject.Properties.Resources.wi0064_48, LocalPosition.X - Size.Width/2, LocalPosition.Y - Size.Height/2);
           //}
       }
   }
}
